package cn.iocoder.yudao.module.game.controller.admin.tripartiteList;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.game.controller.admin.tripartiteList.vo.*;
import cn.iocoder.yudao.module.game.dal.dataobject.tripartiteList.TripartiteListDO;
import cn.iocoder.yudao.module.game.service.tripartiteList.TripartiteListService;

@Tag(name = "管理后台 - 三方列表")
@RestController
@RequestMapping("/game/tripartite-list")
@Validated
public class TripartiteListController {

    @Resource
    private TripartiteListService tripartiteListService;

    @PostMapping("/create")
    @Operation(summary = "创建三方列表")
    @PreAuthorize("@ss.hasPermission('game:tripartite-list:create')")
    public CommonResult<Long> createTripartiteList(@Valid @RequestBody TripartiteListSaveReqVO createReqVO) {
        return success(tripartiteListService.createTripartiteList(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新三方列表")
    @PreAuthorize("@ss.hasPermission('game:tripartite-list:update')")
    public CommonResult<Boolean> updateTripartiteList(@Valid @RequestBody TripartiteListSaveReqVO updateReqVO) {
        tripartiteListService.updateTripartiteList(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除三方列表")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('game:tripartite-list:delete')")
    public CommonResult<Boolean> deleteTripartiteList(@RequestParam("id") Long id) {
        tripartiteListService.deleteTripartiteList(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得三方列表")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('game:tripartite-list:query')")
    public CommonResult<TripartiteListRespVO> getTripartiteList(@RequestParam("id") Long id) {
        TripartiteListDO tripartiteList = tripartiteListService.getTripartiteList(id);
        return success(BeanUtils.toBean(tripartiteList, TripartiteListRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得三方列表分页")
    @PreAuthorize("@ss.hasPermission('game:tripartite-list:query')")
    public CommonResult<PageResult<TripartiteListRespVO>> getTripartiteListPage(@Valid TripartiteListPageReqVO pageReqVO) {
        PageResult<TripartiteListDO> pageResult = tripartiteListService.getTripartiteListPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, TripartiteListRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出三方列表 Excel")
    @PreAuthorize("@ss.hasPermission('game:tripartite-list:export')")
    @OperateLog(type = EXPORT)
    public void exportTripartiteListExcel(@Valid TripartiteListPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<TripartiteListDO> list = tripartiteListService.getTripartiteListPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "三方列表.xls", "数据", TripartiteListRespVO.class,
                        BeanUtils.toBean(list, TripartiteListRespVO.class));
    }

}